﻿using System.Data;
using Utils;
using System;
using Maticsoft.DBUtility;
using System.Text;
public partial class feed : FBasePage
{
    // Fields
    public string strInfo = "";

    // Methods
    protected override void OnLoad(EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            base.Response.ContentType = "text/xml";
            string str = "";
            str = base.Request.Url.AbsoluteUri.Substring(7);
            str = "http://" + str.Substring(0, str.IndexOf('/'));
            string str2 = Helper.GetString(base.Request["ename"], "quanguo");
            if (str2 != string.Empty)
            {
                str2 = " and ename='" + str2 + "' ";
            }
            DataTable table = DbHelperSQL.SelectByFilter("*", "", "Begin_time desc", "(select * from(select team.*,isnull(Category.ename,'quanguo') as ename,isnull(Category.name,'全国') as cityname from Team left join Category on(Team.City_id=Category.Id) ) t3 where end_time>='" + DateTime.Now.ToString() + "' and begin_time<='" + DateTime.Now.ToString() + "' " + str2 + ")t4");
            DateTime now = DateTime.Now;
            if (table.Rows.Count > 0)
            {
                now = Convert.ToDateTime(table.Rows[0]["begin_time"]);
            }
            StringBuilder builder = new StringBuilder();
            builder.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n");
            builder.Append("<!-- generator=\"http://www.asdht.com/ Version 免费版1.0 db " + base.ASSystemArr["siteversion"] + "\" -->\r\n");
            builder.Append("<?xml-stylesheet href=\"\" type=\"text/xsl\"?>\r\n");
            builder.Append("<rss version=\"2.0\">\r\n");
            builder.Append("<channel>\r\n");
            builder.Append("<title><![CDATA[" + base.ASSystem.sitetitle + "]]></title>\r\n");
            builder.Append("<description><![CDATA[" + base.ASSystem.abbreviation + "]]></description>\r\n");
            builder.Append("<link>" + str + "</link>\r\n");
            builder.Append("<lastBuildDate>" + DateTime.Now.DayOfWeek.ToString() + "," + now.ToString() + "</lastBuildDate>\r\n");
            builder.Append("<generator>" + base.ASSystem.Siteversion + "</generator>\r\n");
            builder.Append("<image>");
            builder.Append("<url>" + str + base.ASSystem.headlogo + "</url>\r\n");
            builder.Append("<title><![CDATA[" + base.ASSystem.sitename + "]]></title>\r\n");
            builder.Append("<link>" + base.ASSystem.sitename + "</link>\r\n");
            builder.Append("<description>Feed provided by asdnt</description>\r\n");
            builder.Append("</image>\r\n");
            string str3 = " Team_type='normal' ";
            if ((base.Request["cityid"] != null) && (base.Request["cityid"].ToString() != ""))
            {
                str3 = str3 + " and City_id=" + base.Request["cityid"].ToString();
            }
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    DataRow row = table.Rows[i];
                    builder.Append("<item>");
                    builder.Append("<title><![CDATA[" + row["Title"].ToString() + "]]></title>\r\n");
                    builder.Append("<link>" + str + "/team.aspx?id=" + row["id"].ToString() + "</link>\r\n");
                    builder.Append(string.Concat(new object[] { "<description><![CDATA[", row["Summary"], "<br/> <img src='", str, row["Image"], "'>", row["Detail"], "<br/>]]></description>\r\n" }));
                    Maticsoft.Model.UserInfo model = new Maticsoft.BLL.UserInfo().GetModel(int.Parse(row["User_id"].ToString()));
                    if (model != null)
                    {
                        builder.Append("<author>" + model.Realname + "</author>\r\n");
                    }
                    builder.Append("<city>" + table.Rows[i]["cityname"].ToString() + "</city>\r\n");
                    builder.Append("</item>\r\n");
                }
            }
            builder.Append("</channel>\r\n");
            builder.Append("</rss>\r\n");
            base.Response.Clear();
            base.Response.Write(builder.ToString());
            base.Response.End();
        }
    }
}


